#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=100, maxm=100;

class Graph {
public:
  int n, m, ind[maxn+1], link[2*maxn-1], to[2*maxn-1], col[maxn+1], dep[maxn+1], fa[maxn+1];

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  void build(int o, int fa) {
    this->fa[o] = fa;
    dep[o] = dep[fa]+1;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	build(to[i], o);
      }
    }
  }

  int solve(int u, int v, int a, int b) {
    static int ans[maxn+1], ver;
    ver++;

    if (dep[u]<dep[v]) {
      int temp;
      temp=u, u=v, v=temp;
    }
    ans[0]=0;
    for (; dep[fa[u]]>=dep[v]; u=fa[u]) {
      if (u!=0) {
	if (col[u]!=a) {
	  if (ans[col[u]]!=ver) {
	    ans[col[u]] = ver;
	    ans[0]++;
	  }
	} else {
	  if (ans[b]!=ver) {
	    ans[b] = ver;
	    ans[0]++;
	  }
	}
      }
    }
    if (u==v) {
      if (u!=0) {
	if (col[u]!=a) {
	  if (ans[col[u]]!=ver) {
	    ans[col[u]] = ver;
	    ans[0]++;
	  }
	} else {
	  if (ans[b]!=ver) {
	    ans[b] = ver;
	    ans[0]++;
	  }
	}
      }
      return ans[0];
    }
    for (; u!=v; u=fa[u], v=fa[v]) {
      if (u!=0) {
	if (col[u]!=a) {
	  if (ans[col[u]]!=ver) {
	    ans[col[u]] = ver;
	    ans[0]++;
	  }
	} else {
	  if (ans[b]!=ver) {
	    ans[b] = ver;
	    ans[0]++;
	  }
	}
      }

      if (v!=0) {
	if (col[v]!=a) {
	  if (ans[col[v]]!=ver) {
	    ans[col[v]] = ver;
	    ans[0]++;
	  }
	} else {
	  if (ans[b]!=ver) {
	    ans[b] = ver;
	    ans[0]++;
	  }
	}
      }
    }
    if (u!=0) {
      if (col[u]!=a) {
	if (ans[col[u]]!=ver) {
	  ans[col[u]] = ver;
	  ans[0]++;
	}
      } else {
	if (ans[b]!=ver) {
	  ans[b] = ver;
	  ans[0]++;
	}
      }
    }
    return ans[0];
  }
};

int main() {
#ifdef DEBUG
  freopen("0.in", "r", stdin);
  freopen("0.out", "w", stdout);
#endif

  static Graph g;
  int n, m;
  scanf("%d %d", &n, &m);
  g.n = n;
  for (int i=1; i<=n; i++) {
    scanf("%d", &g.col[i]);
  }
  for (int i=1; i<=n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g.addSide(u, v);
    g.addSide(v, u);
  }

  g.build(0, 0);

  for (int i=1; i<=m; i++) {
    int u, v, a, b;
    scanf("%d %d %d %d", &u, &v, &a, &b);
    printf("%d\n", g.solve(u, v, a, b));
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
